﻿using System;
using System.Linq;
using ElectronicCommerce.Framework.Configuration;
using ElectronicCommerce.Framework.Configuration.Entities;

namespace ElectronicCommerce.Framework.ExceptionManagement
{
    public class MessageException : Exception
    {
        private Enum m_MessageAlias;
        private string m_MessageText;
        private string m_MessageDescription;

        public MessageException(Enum keyAlias)
            : base(keyAlias.ToString())
        {
            m_MessageAlias = keyAlias;

            MessageResource tempMessage = null;
            if (ConfigHelper.MessageConfig.MessageList.Contains(base.Message))
            {
                tempMessage = ConfigHelper.MessageConfig.MessageList[base.Message];
            }

            if (tempMessage != null)
            {
                m_MessageText = tempMessage.Text;
                if (tempMessage.DescriptionList != null && tempMessage.DescriptionList.Count > 0)
                {
                    m_MessageDescription = tempMessage.DescriptionList.First().Text;
                }
            }
        }

        public Enum MessageAlias
        {
            get { return m_MessageAlias; }
        }

        public string MessageText
        {
            get { return m_MessageText; }
        }

        public string MessageDescription
        {
            get { return m_MessageDescription; }
        }
    }
}
